package com.wc.算法基础课.D第四讲数学知识.快速幂.转圈游戏;

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/4/2 0:02
 * @description https://www.acwing.com/problem/content/506/
 */
public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static int n, m, x, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        x = sc.nextInt();
        out.println((m * qkm(10, k, n) % n + x) % n);
        out.flush();
    }

    static long qkm(long a, int b, int p) {
        long res = 1;
        while (b > 0) {
            if ((b & 1) == 1) res = res * a % p;
            b >>= 1;
            a = a * a % p;
        }
        return res;
    }
}

